package com.qzsoft.system.modules.sysmenu.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import com.qzsoft.jeemis.repository.sys.dao.BasicMenuDao;
import com.qzsoft.jeemis.repository.sys.entity.BasicMenuEntity;
import com.qzsoft.system.modules.sysmenu.mapper.SysMenuMapper;
import com.qzsoft.system.modules.sysmenu.service.SysMenuService;

/**
 * @ClassName SysMenuServiceImpl
 * @Description 系统菜单业务接口实现
 * @author linhuawei
 * @since 2022-05-17
 */
@Service
public class SysMenuServiceImpl implements SysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Autowired
    private BasicMenuDao menuDao;

    @Override
    public List<String> getPathName(Map<String, Object> map) {
        List<String> sbf = new ArrayList<>();
        Map<String, Object> pathName = sysMenuMapper.getPathName(map);
        if (!org.springframework.util.StringUtils.isEmpty(pathName)) {
            if (null != pathName.get("title")) {
                sbf.add(String.valueOf(pathName.get("title")));
            }
            if (null != pathName.get("pname")) {
                sbf.add(String.valueOf(pathName.get("pname")));
            }
            if (!ObjectUtils.isEmpty(pathName.get("ppid"))
                    && !StringUtils.equals("0", String.valueOf(map.get("ppid")))) {
                BasicMenuEntity ppid = menuDao.selectById(String.valueOf(pathName.get("ppid")));
                if (!ObjectUtils.isEmpty(ppid)) {
                    sbf.add(ppid.getTitle());
                }
            }
        }
        Collections.reverse(sbf);
        return sbf;
    }

    @Override
    public List<String> getPermissionsList() {
        return sysMenuMapper.getPermissionsList();
    }

    @Override
    public List<String> getUserPermissionsList(Long userId) {
        return sysMenuMapper.getUserPermissionsList(userId);
    }

}
